#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=1e5+10;
ll neat=0;
struct node
{
	ll t;//时间
	ll d;//distance 距离
}cow[N];
bool cmp(node&a,node&b)
{
	return a.t*b.d<b.t*a.d;
}
int main()
{
	int n;cin>>n;

	for(int i=1;i<=n;i++)
	{
		cin>>cow[i].t>>cow[i].d;
		neat+=cow[i].d;
	}
	ll ret=0;
	sort(cow+1,cow+n+1,cmp);
	for(int i=1;i<=n;i++)
	{
		neat-=cow[i].d;
		ret+=cow[i].t*neat*2;
	}
	cout<<ret<<endl;
}